package com.ymatou.iapi.accounting.testcase;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.accounting.parameter.*;
import com.ymatou.iapi.accounting.service.*;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P3;
import com.ymttest.business.service.AccountCallServiceV2;
import com.ymttest.database.model.Account;
import com.ymttest.database.sqlwapper.AccountWapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.YMTDateUtil;

/**
 * 获取资金账户接口 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_GetAccount {
	private static GetAccountBean getaccountBean;
	private static GetAccountCall getaccountCall;
	private static String accountid1;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取资金账户接口");
		try {
			accountid1 = AccountCallServiceV2.getAccountId(Integer.valueOf(EnvSetup.getData("accountuid1")));
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Before
	public void caseUp() {
		getaccountBean = new GetAccountBean();
		getaccountCall = new GetAccountCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getaccountCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetAccount_001() {
		Logger.start(true, "获取资金账户成功");
		try {
			String aid = accountid1;
			getaccountBean.setAccountId(aid);
			getaccountBean.setAppId("AutoTest");
			getaccountCall.setData(getaccountBean);
			getaccountCall.callService();

			List<Account> aids = new AccountWapper().selectAccountInfo(aid);
			AccountBean Account = getaccountCall.getReturnAccount();
			if (aids.size() > 0) {
				Logger.verifyEquals((Integer) aids.get(0).getUserId(), Account.getUserId(), "验证接口返回userid跟数据库是否一致");
				Logger.verifyEquals((Integer) aids.get(0).getStatus(), Account.getStatus(), "验证接口返回Action跟数据库是否一致");
				Logger.verifyEquals((Integer) aids.get(0).getCurrencyType(), Account.getCurrencyType(),
						"验证接口返回CurrencyType跟数据库是否一致");
				Logger.verifyEquals((Integer) aids.get(0).getAccountType(), Account.getAccountType(),
						"验证接口返回AccountType跟数据库是否一致");
				Logger.verifyEquals(0,
						((BigDecimal) aids.get(0).getAvailAmount()).compareTo(Account.getAvailAmount()),
						"验证接口返回AvailAmount:" + Account.getAvailAmount() + "跟数据库是否一致");
				Logger.verifyEquals(0,
						((BigDecimal) aids.get(0).getFreezeAmount()).compareTo(Account.getFreezeAmount()),
						"验证接口返回FreezeAmount:" + Account.getFreezeAmount() + "跟数据库是否一致");
				Logger.verifyEquals((String) aids.get(0).getAccountId(), Account.getAccountId(),
						"验证接口返回AccountInfoId跟数据库是否一致");
				String ct=YMTDateUtil.getFormatTime(aids.get(0).getCreateTime(), YMTDateUtil.YMDHMSS);
				Logger.verifyEquals(ct.substring(0, 19), Account.getCreateTime().substring(0, 19),
						"验证接口返回CreateTime跟数据库是否一致");
				String ut=YMTDateUtil.getFormatTime(aids.get(0).getUpdateTime(), YMTDateUtil.YMDHMSS);
				Logger.verifyEquals(ut.substring(0, 19), Account.getUpdateTime().substring(0, 19),
						"验证接口返回UpdateTime跟数据库是否一致");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_GetAccount_002() {
		Logger.start(false, "账户编号不存在,获取资金账户返回结果为空");
		try {
			String aid = "0000";
			getaccountBean.setAccountId(aid);
			getaccountBean.setAppId("AutoTest");
			getaccountCall.setData(getaccountBean);
			getaccountCall.callService();

			Logger.verifyEquals("null", getaccountCall.getData(), "验证接口返回data为null");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_GetAccount_003() {
		Logger.start(false, "账户编号为空,获取资金账户返回结果为空");
		try {
			String aid = "0000";
			// getaccountBean.setAccountId(aid);
			getaccountBean.setAppId("AutoTest");
			getaccountCall.setData(getaccountBean);
			getaccountCall.callService();

			Logger.verifyEquals("null", getaccountCall.getData(), "验证接口返回data为null");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_GetAccount_004() {
		Logger.start(false, "Appid为空,获取资金账户失败");
		try {
			String aid = "00010020000000";
			getaccountBean.setAccountId(aid);
			// getaccountBean.setAppId("AutoTest");
			getaccountCall.setData(getaccountBean);
			getaccountCall.callService();

			Logger.verifyEquals("null", getaccountCall.getData(), "验证接口返回data为null");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}